using System;
using Glade;
using Gtk;

namespace Parking
{
	public class Borne
	{
		public Borne (String n, Acces a)
		{
			nom = n;
			acces = a;
			Glade.XML gxml = new Glade.XML (null, "Parking.accueildp.glade", "fenetre", null);
			gxml.Autoconnect (this);
			welcome.Text += "\n" + acces.nom + " - " + nom;
			maj_label();
		}
		
		public Acces acces {
			get; private set;
		}
		
		public String nom {
			get; private set;
		}
		
		[Glade.Widget]
		Label welcome;
		
		[Glade.Widget]
		Label dispo;
		
		public void on_garer_clicked (System.Object obj, EventArgs e)
		{
			Ticket t = acces.garerVoiture(new Voiture());
			Dialog dialog = null;
			try {
    			dialog = new Dialog (
        			"Ticket",
        			null,
        			DialogFlags.DestroyWithParent | DialogFlags.Modal,
        			"Ok", ResponseType.Ok
    			);
				if (t != null) {
					dialog.VBox.Add (new Label ("Voiture garée\nNuméro du ticket : " + t.numero));
				} else {
					dialog.VBox.Add (new Label ("Plus de places disponibles !"));
				}
    			
	    		dialog.ShowAll ();
    			dialog.Run ();
			} finally {
    			if (dialog != null)
        			dialog.Destroy ();
			}
		}
		
		public void on_recup_clicked (System.Object obj, EventArgs e)
		{
			new DlgReprendre(this);
		}
		
		public void maj_label() {
			dispo.Text = "Places disponibles : " + acces.parking.nbPlacesRestantes + "/" + acces.parking.nbPlacesTotales;
		}
		
		public Ticket reprendreVoiture (int pNumeroTicket){
			return acces.reprendreVoiture(pNumeroTicket);
		}
	}
}
